package com.news.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.news.bean.Setinfo;
import com.news.dao.SetinfoDao;
import com.news.util.DButil;

public class SetinfoDaoImpl implements SetinfoDao{
	private final String SETINFO = "insert into setinfo(title,keyword,setauth) values(?,?,?)";
	private final String SETINFO_LIST = "select * from setinfo";
	public int setinfo(Setinfo si) {
		int i = 1;
		int ret = 0;
		//Setinfo si = new Setinfo();
		try {
			PreparedStatement pstmt = DButil.getPreparedStatement(SETINFO);
			pstmt.setString(i++, si.getTitle());
			pstmt.setString(i++, si.getKeyword());
			pstmt.setString(i++, si.getSetauth());
			ret = pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DButil.close();
		}
		
		return ret;
	}

	public List<Setinfo> getSetinfoList(Map map) {
		List<Setinfo> list = new ArrayList<Setinfo>();
		try {
			PreparedStatement pstmt = DButil.getPreparedStatement(SETINFO_LIST);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				Setinfo si = new Setinfo();
				si.setId(rs.getInt("id"));
				si.setKeyword(rs.getString("keyword"));
				si.setTitle(rs.getString("title"));
				si.setSetauth(rs.getString("setauth"));
				list.add(si);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DButil.close();
		}
		return list;
	}

}
